import Vue from 'vue'
import Vuex from 'vuex'
import {
	request
} from '../common/http.js'


Vue.use(Vuex);

const store = new Vuex.Store({
	// 存放状态
	state: {
		"username": "546L6aaW6YO9",
		"version": "v1.0.0",
		"start-time": "MjAyMi0wMi0wOA==",
		"university": "5reu5Y2X5biI6IyD5a2m6Zmi",
		"stu-code": "MTgwODA0MDE0OA==",
		"pageSize": 30,
		// "url": 'https://localhost:8080',
		"url": "https://www.wangsd.xyz:8080",
		
		"code": null,
		"userInfo": {},
		"menuList": [],
		"isLogin": false,
		"token": null,
		"rightMenus": [],
		"userRightMenus": [],
		
		"currentBookUserId": -1,
	},

	getters: {
		// sotre getter不支持lambda
		nickName(state) {
			return state.userInfo.nickName
		},
		nickname(state) {
			return state.userInfo.nickName
		},
		avatarUrl(state) {
			return state.userInfo.avatarUrl
		},
		avatarBgUrl(state) {
			return `background-image: url(${state.userInfo.avatarUrl})`
		},
		gender(state) {
			return state.userInfo.gender
		},
		id(state) {
			return state.userInfo.id
		},
		url(state) {
			return state.url
		}
	},

	//vuex需要将异步方法放到actions中, 同步方法放到mutations中 
	actions: {

	},
	mutations: {
		setCode: (state, code) => {
			state.code = code
		},
		setUserToken: (state, token) => {
			state.token = token
		},
		setUserInfo: (state, userInfo) => {
			state.userInfo = userInfo
		},
		setMenuList: (state, menuList) => {
			state.menuList = menuList
		},
		setLoginStatus: (state, isLogin) => {
			state.isLogin = isLogin
		},
		setCurrentBookUserId: (state, uid) => {
			state.currentBookUserId = uid
		},
		setRightMenus: (state, rightMenus) => {
			state.rightMenus = rightMenus
		},
		setUserRightMenus: (state, userRightMenus) => {
			state.userRightMenus = userRightMenus
		}
	}
})


export default store
